/*********************************************************
 * copyright xinbohit.com 版权所有 
 * 开发人员：IvanYu
 * 创建时间：2014/8/22 9:30:18
 * 描述说明：
 * 
 * 更改历史：
 * 
 * *******************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LEARNREN.COM.Entity;
using LEARNREN.COM.DAL;
using LEARNREN.COM.TOOL;

namespace LEARNREN.COM.BLL
{
    public class JobLogic : LogicBase<Job>
    {
        public JobLogic()
        {

        }

        public JobLogic(DB4ODALClient client)
            : base(client)
        {

        }

        public Job GetById(long id)
        {
            return GetList(p => p.Id == id).FirstOrDefault();
        }


        /// <summary>
        /// 获取文章的URL地址,带网站配置中设置的域名的
        /// </summary>
        /// <param name="a">文章</param>
        /// <returns></returns>
        public string GetURL(Job a)
        {
            Catalogue c = BasicCache.AllCatalogueList.FirstOrDefault(p => p.Id == a.CatalogueId);
            return GetURL(a, c);
        }

        /// <summary>
        /// 不带域名的URL地址，以“/”表示根目录的绝对路径
        /// </summary>
        /// <param name="a">文章</param>
        /// <returns></returns>
        public string GetURL2(Job a)
        {
            Catalogue c = BasicCache.AllCatalogueList.FirstOrDefault(p => p.Id == a.CatalogueId);
            return GetURL2(a, c);
        }

        /// <summary>
        /// 获取文章的url地址,带网站配置中设置的域名的
        /// </summary>
        /// <param name="a">文章</param>
        /// <param name="c">文章所属的栏目</param>
        /// <returns></returns>
        public string GetURL(Job a, Catalogue c)
        {
            if (BasicCache.SiteConfig.IsStaticEnable)
            {
                return GetStaticURL(a, c);
            }
            else
            {
                return GetDynamicURL(a);
            }
        }

        /// <summary>
        /// 不带域名的URL地址，以“/”表示根目录的绝对路径
        /// </summary>
        /// <param name="a">文章</param>
        /// <param name="c">文章所述的栏目</param>
        /// <returns></returns>
        public string GetURL2(Job a, Catalogue c)
        {
            if (BasicCache.SiteConfig.IsStaticEnable)
            {
                return GetStaticURL2(a, c);
            }
            else
            {
                return GetDynamicURL2(a);
            }
        }

        private string GetStaticURL(Job a, Catalogue c)
        {
            return string.Format("{0}{1}{2}/jobs/{3}.html",
                                  BasicCache.SiteConfig.SiteUrl.ChangeToHttpStart(),
                                  System.Web.VirtualPathUtility.ToAbsolute("~/"),
                                  c.HtmlPath,
                                  a.Id);
        }

        private string GetDynamicURL(Job a)
        {
            return string.Format("{0}{1}ShowJob.aspx?id={2}",
                                BasicCache.SiteConfig.SiteUrl.ChangeToHttpStart(),
                                System.Web.VirtualPathUtility.ToAbsolute("~/"),
                                a.Id);
        }

        private string GetStaticURL2(Job a, Catalogue c)
        {
            return string.Format("{0}{1}/jobs/{2}.html",
                                  System.Web.VirtualPathUtility.ToAbsolute("~/"),
                                  c.HtmlPath,
                                  a.Id);
        }

        private string GetDynamicURL2(Job a)
        {
            return string.Format("{0}ShowJob.aspx?id={1}",
                                System.Web.VirtualPathUtility.ToAbsolute("~/"),
                                a.Id);
        }
    }
}
